package cn.com.oceansoft.business.os.service.impl;

import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.base.entity.Result;
import cn.com.oceansoft.business.os.entity.Game;
import cn.com.oceansoft.business.os.persistence.IGameMapper;
import cn.com.oceansoft.business.os.service.IGameService;
import cn.com.oceansoft.nos.common.util.web.PageUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by lenovo on 2018/1/3.
 */
@Service
public class GameServiceImpl implements IGameService {
    @Resource
    private IGameMapper gameMapper;
    @Override
    public Result save(Game game) {
        Result result=new Result();
        try{
            gameMapper.save(game);
            result.setSucc(true);
            result.setMsg("添加成功！");
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        result.setSucc(false);
        result.setMsg("添加失败");
        return result;
    }

    @Override
    public Pager<Game> findListByPage(Query query) {
        try{
            PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
            return PageUtil.page2pager((Page<Game>) gameMapper.findListByPage(query), query);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Game findOne(String dbid) {
        try{
           return gameMapper.findOne(dbid);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Result update(Game game) {
        Result result=new Result();
        try{
           gameMapper.update(game);
            result.setSucc(true);
            result.setMsg("编辑成功");
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        result.setSucc(false);
        result.setMsg("编辑失败");
        return result;
    }

    @Override
    public Result delete(String dbid) {
        Result result=new Result();
        try{
            gameMapper.delete(dbid);
            result.setSucc(true);
            result.setMsg("删除成功");
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        result.setSucc(false);
        result.setMsg("删除失败");
        return result;
    }
}
